function imgpreload(imgs, settings) {
    
    // settings = { each:Function, all:Function }
    if (settings instanceof Function) { settings = { all: settings }; }

    // use of typeof required
    // https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Operators/Special_Operators/Instanceof_Operator#Description
    if (typeof imgs == "string") { imgs = [imgs]; }

    var loaded = [];
    var t = imgs.length;
    var i = 0;

    for (i; i < t; i++) {
        var img = new Image();
        img.onload = function() {
            loaded.push(this);
            if (settings.each instanceof Function) { settings.each.call(this); }
            if (loaded.length >= t && settings.all instanceof Function) { settings.all.call(loaded); }
        };
        img.src = imgs[i];
    }
}

if (typeof jQuery != "undefined") {
    (function($) {

        // extend jquery (because i love jQuery)
        $.imgpreload = imgpreload;

        // public
        $.fn.imgpreload = function(settings) {
            settings = $.extend({}, $.fn.imgpreload.defaults, (settings instanceof Function) ? { all: settings} : settings);

            this.each(function() {
                var elem = this;

                imgpreload($(this).attr('src'), function() {
                    if (settings.each instanceof Function) { settings.each.call(elem); }
                });
            });

            // declare urls and loop here (loop a second time) to prevent
            // pollution of above closure with unnecessary variables

            var urls = [];

            this.each(function() {
                urls.push($(this).attr('src'));
            });

            var selection = this;

            imgpreload(urls, function() {
                if (settings.all instanceof Function) { settings.all.call(selection); }
            });

            return this;
        };

        // public
        $.fn.imgpreload.defaults =
		{
		    each: null // callback invoked when each image in a group loads
			, all: null // callback invoked when when the entire group of images has loaded
		};

    })(jQuery);
}

var loadedImages = -1;

function currentLanguageFc() {
    $('#languageChangerList').children().each(function(i, el) {
        if ($(el).val() == '-1') {
            currentLanguage = $(this).text();
        }
    });
    return getTranslation("loading", currentLanguage);
}

$.imgpreload([
        './Content/Assets/map/ajax-loader.gif',
        './Content/Assets/map/map01.jpg',
        './Content/Assets/map/map02.jpg',
        './Content/Assets/map/map03.jpg',
        './Content/Assets/map/map04.jpg',
        './Content/Assets/map/map05.jpg',
        './Content/Assets/map/map06.jpg',
        './Content/Assets/map/map07.jpg',
        './Content/Assets/map/map08.jpg',
        './Content/Assets/map/map09.jpg',
        './Content/Assets/map/map10.jpg',
        './Content/Assets/map/map11.jpg',
        './Content/Assets/map/map12.jpg',
        './Content/Assets/map/map13.jpg',
        './Content/Assets/map/map14.jpg',
        './Content/Assets/map/map15.jpg',
        './Content/Assets/map/map16.jpg',
        './Content/Assets/map/map17.jpg',
        './Content/Assets/map/map18.jpg',
        './Content/Assets/map/map19.jpg',
        './Content/Assets/map/map20.jpg',
        './Content/Assets/map/map21.jpg',
        './Content/Assets/map/map22.jpg',
        './Content/Assets/map/map23.jpg',
        './Content/Assets/map/map24.jpg',
        './Content/Assets/map/map25.jpg',
        './Content/Assets/map/map26.jpg',
        './Content/Assets/map/map27.jpg',
        './Content/Assets/map/map28.jpg',
        './Content/Assets/map/map29.jpg',
        './Content/Assets/map/map30.jpg',
        './Content/Assets/map/map31.jpg',
        './Content/Assets/map/map32.jpg',
        './Content/Assets/map/map33.jpg',
        './Content/Assets/map/map34.jpg',
        './Content/Assets/map/map35.jpg',
        './Content/Assets/map/map36.jpg',
        './Content/Assets/map/map37.jpg',
        './Content/Assets/map/map38.jpg',
        './Content/Assets/map/map39.jpg',
        './Content/Assets/map/map40.jpg',
        './Content/Assets/map/map41.jpg'
    ],

	{
	    each: function() {
	    loadedImages++;
	        $("#mapContainer").html("<div class=\"loadingImages\"><img src=\"./Content/Assets/map/ajax-loader.gif\" alt=\"\" /><span>" + currentLanguageFc() + ": " + loadedImages + "/41</span></div>");
	    },
	    all: function() {
	        $("#mapContainer").html("<img src=\"./Content/Assets/map/map.jpg\" usemap=\"#worldMap\" border=0>");
	    }
	});


function mapOnMouseOver(countryId) {
    if (countryId < 10) {
        countryId = "0" + countryId;
    }
    var html = "<img src=\"./Content/Assets/map/map"+countryId+".jpg\" usemap=\"#worldMap\" border=0>";
    $("#mapContainer img").hide().attr('src', "./Content/Assets/map/map"+countryId+".jpg").fadeIn('fast');

    
}

function mapOnMouseOut() {
    $("#mapContainer img").fadeOut('fast', function() {
        $("#mapContainer").html("<img src=\"./Content/Assets/map/map.jpg\" usemap=\"#worldMap\" border=0>");
    });

}

function dropDownChange(sender) {
    var dropDownValue = sender.value;
    window.location = dropDownValue;
}